﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace Ledshow
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        //-------------------------------------------------------------------------
        [DllImport("user32.dll")]
        private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
        //-------------------------------------------------------------------------

        [STAThread]
        static void Main()
        {
            //-------------------------------------------------------------------------
            string appName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
            Mutex mtx = new Mutex(true, appName, out bool isNewInstance);
            
            if (!isNewInstance)
            {
                Process[] myProcess = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(appName));
                if (null != myProcess.FirstOrDefault())
                {
                    ShowWindow(myProcess.FirstOrDefault().MainWindowHandle, 1);
                }
                _ = MessageBox.Show("程序已经已经运行了，不用再点了.", "提示");

            }
            else
            {
             //-------------------------------------------------------------------------
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            
        }
    }
}
